# Library
library(sandwich)
library(SimDesign)
library(interplot)
library(ggpubr)

# Read in the data
load("Data_experiments.RData")

set.seed(832)

###########################
# H1
###########################

# Labour: MR vs. Control
labLikeMod_prepost <- lm(likeL_post ~ mrcontrol + likeL_pre, data=dat_lab)
labLikeMod_diff <- lm(likeLdiff ~ mrcontrol, data=dat_lab)

# Labour: MR vs PR
labLikeModpr_prepost <- lm(likeL_post ~ mrpr + likeL_pre, dat_lab) 
labLikeModpr_diff <- lm(likeLdiff ~ mrpr, dat_lab)

# Conservative: MR vs. Control
conLikeMod_prepost <- lm(likeC_post ~ mrcontrol + likeC_pre, data=dat_con)
conLikeMod_diff <- lm(likeCdiff ~ mrcontrol, data=dat_con)

# Conservative: MR vs PR
conLikeModpr_prepost <- lm(likeC_post ~ mrpr + likeC_pre, dat_con)
conLikeModpr_diff <- lm(likeCdiff ~ mrpr, dat_con)

# Labour: simulated results

labLikeMod_prepost_vcov <- vcovHC(labLikeMod_prepost, type="HC1")
labLikeMod_prepost_betas <- rmvnorm(n=100000,mean=labLikeMod_prepost$coefficients,sigma=labLikeMod_prepost_vcov)
labLikeMod_prepost_betas <- labLikeMod_prepost_betas[,c("mrcontrol")]
labLikeMod_prepost_data <- data.frame(dim="Pre-post 1",mrcontrol=1)
labLikeMod_prepost_data$lower95 <- labLikeMod_prepost_data$upper95 <- labLikeMod_prepost_data$lower90 <- labLikeMod_prepost_data$upper90 <- labLikeMod_prepost_data$est <- NA
for(i in 1:nrow(labLikeMod_prepost_data)){
  labLikeMod_prepost_dist <- labLikeMod_prepost_data[i,"mrcontrol"] * labLikeMod_prepost_betas
  labLikeMod_prepost_data[i,"lower95"] <- quantile(labLikeMod_prepost_dist,0.025)
  labLikeMod_prepost_data[i,"lower90"] <- quantile(labLikeMod_prepost_dist,0.05)
  labLikeMod_prepost_data[i,"est"] <- quantile(labLikeMod_prepost_dist,0.5)
  labLikeMod_prepost_data[i,"upper90"] <- quantile(labLikeMod_prepost_dist,0.95)
  labLikeMod_prepost_data[i,"upper95"] <- quantile(labLikeMod_prepost_dist,0.975)
}

labLikeMod_diff_vcov <- vcovHC(labLikeMod_diff, type="HC1")
labLikeMod_diff_betas <- rmvnorm(n=100000,mean=labLikeMod_diff$coefficients,sigma=labLikeMod_diff_vcov)
labLikeMod_diff_betas <- labLikeMod_diff_betas[,c("mrcontrol")]
labLikeMod_diff_data <- data.frame(dim="Pre-post 2",mrcontrol=1)
labLikeMod_diff_data$lower95 <- labLikeMod_diff_data$upper95 <- labLikeMod_diff_data$lower90 <- labLikeMod_diff_data$upper90 <- labLikeMod_diff_data$est <- NA
for(i in 1:nrow(labLikeMod_diff_data)){
  labLikeMod_diff_dist <- labLikeMod_diff_data[i,"mrcontrol"] * labLikeMod_diff_betas
  labLikeMod_diff_data[i,"lower95"] <- quantile(labLikeMod_diff_dist,0.025)
  labLikeMod_diff_data[i,"lower90"] <- quantile(labLikeMod_diff_dist,0.05)
  labLikeMod_diff_data[i,"est"] <- quantile(labLikeMod_diff_dist,0.5)
  labLikeMod_diff_data[i,"upper90"] <- quantile(labLikeMod_diff_dist,0.95)
  labLikeMod_diff_data[i,"upper95"] <- quantile(labLikeMod_diff_dist,0.975)
}

labLikeModpr_prepost_vcov <- vcovHC(labLikeModpr_prepost, type="HC1")
labLikeModpr_prepost_betas <- rmvnorm(n=100000,mean=labLikeModpr_prepost$coefficients,sigma=labLikeModpr_prepost_vcov)
labLikeModpr_prepost_betas <- labLikeModpr_prepost_betas[,c("mrpr")]
labLikeModpr_prepost_data <- data.frame(dim="Pre-post 1",mrpr=1)
labLikeModpr_prepost_data$lower95 <- labLikeModpr_prepost_data$upper95 <- labLikeModpr_prepost_data$lower90 <- labLikeModpr_prepost_data$upper90 <- labLikeModpr_prepost_data$est <- NA
for(i in 1:nrow(labLikeModpr_prepost_data)){
  labLikeModpr_prepost_dist <- labLikeModpr_prepost_data[i,"mrpr"] * labLikeModpr_prepost_betas
  labLikeModpr_prepost_data[i,"lower95"] <- quantile(labLikeModpr_prepost_dist,0.025)
  labLikeModpr_prepost_data[i,"lower90"] <- quantile(labLikeModpr_prepost_dist,0.05)
  labLikeModpr_prepost_data[i,"est"] <- quantile(labLikeModpr_prepost_dist,0.5)
  labLikeModpr_prepost_data[i,"upper90"] <- quantile(labLikeModpr_prepost_dist,0.95)
  labLikeModpr_prepost_data[i,"upper95"] <- quantile(labLikeModpr_prepost_dist,0.975)
}

labLikeModpr_diff_vcov <- vcovHC(labLikeModpr_diff, type="HC1")
labLikeModpr_diff_betas <- rmvnorm(n=100000,mean=labLikeModpr_diff$coefficients,sigma=labLikeModpr_diff_vcov)
labLikeModpr_diff_betas <- labLikeModpr_diff_betas[,c("mrpr")]
labLikeModpr_diff_data <- data.frame(dim="Pre-post 2",mrpr=1)
labLikeModpr_diff_data$lower95 <- labLikeModpr_diff_data$upper95 <- labLikeModpr_diff_data$lower90 <- labLikeModpr_diff_data$upper90 <- labLikeModpr_diff_data$est <- NA
for(i in 1:nrow(labLikeModpr_diff_data)){
  labLikeModpr_diff_dist <- labLikeModpr_diff_data[i,"mrpr"] * labLikeModpr_diff_betas
  labLikeModpr_diff_data[i,"lower95"] <- quantile(labLikeModpr_diff_dist,0.025)
  labLikeModpr_diff_data[i,"lower90"] <- quantile(labLikeModpr_diff_dist,0.05)
  labLikeModpr_diff_data[i,"est"] <- quantile(labLikeModpr_diff_dist,0.5)
  labLikeModpr_diff_data[i,"upper90"] <- quantile(labLikeModpr_diff_dist,0.95)
  labLikeModpr_diff_data[i,"upper95"] <- quantile(labLikeModpr_diff_dist,0.975)
}

# Average effect size of Labour results
mean(c(labLikeMod_prepost_data[1,"est"]/sd(labLikeMod_prepost$model[,c("likeL_post")]),
       labLikeMod_diff_data[1,"est"]/sd(labLikeMod_diff$model[,c("likeLdiff")]),
       labLikeModpr_prepost_data[1,"est"]/sd(labLikeModpr_prepost$model[,c("likeL_post")]),
       labLikeModpr_diff_data[1,"est"]/sd(labLikeModpr_diff$model[,c("likeLdiff")])))

# Conservative: simulated results

conLikeMod_prepost_vcov <- vcovHC(conLikeMod_prepost, type="HC1")
conLikeMod_prepost_betas <- rmvnorm(n=100000,mean=conLikeMod_prepost$coefficients,sigma=conLikeMod_prepost_vcov)
conLikeMod_prepost_betas <- conLikeMod_prepost_betas[,c("mrcontrol")]
conLikeMod_prepost_data <- data.frame(dim="Pre-post 1",mrcontrol=1)
conLikeMod_prepost_data$lower95 <- conLikeMod_prepost_data$upper95 <- conLikeMod_prepost_data$lower90 <- conLikeMod_prepost_data$upper90 <- conLikeMod_prepost_data$est <- NA
for(i in 1:nrow(conLikeMod_prepost_data)){
  conLikeMod_prepost_dist <- conLikeMod_prepost_data[i,"mrcontrol"] * conLikeMod_prepost_betas
  conLikeMod_prepost_data[i,"lower95"] <- quantile(conLikeMod_prepost_dist,0.025)
  conLikeMod_prepost_data[i,"lower90"] <- quantile(conLikeMod_prepost_dist,0.05)
  conLikeMod_prepost_data[i,"est"] <- quantile(conLikeMod_prepost_dist,0.5)
  conLikeMod_prepost_data[i,"upper90"] <- quantile(conLikeMod_prepost_dist,0.95)
  conLikeMod_prepost_data[i,"upper95"] <- quantile(conLikeMod_prepost_dist,0.975)
}

conLikeMod_diff_vcov <- vcovHC(conLikeMod_diff, type="HC1")
conLikeMod_diff_betas <- rmvnorm(n=100000,mean=conLikeMod_diff$coefficients,sigma=conLikeMod_diff_vcov)
conLikeMod_diff_betas <- conLikeMod_diff_betas[,c("mrcontrol")]
conLikeMod_diff_data <- data.frame(dim="Pre-post 2",mrcontrol=1)
conLikeMod_diff_data$lower95 <- conLikeMod_diff_data$upper95 <- conLikeMod_diff_data$lower90 <- conLikeMod_diff_data$upper90 <- conLikeMod_diff_data$est <- NA
for(i in 1:nrow(conLikeMod_diff_data)){
  conLikeMod_diff_dist <- conLikeMod_diff_data[i,"mrcontrol"] * conLikeMod_diff_betas
  conLikeMod_diff_data[i,"lower95"] <- quantile(conLikeMod_diff_dist,0.025)
  conLikeMod_diff_data[i,"lower90"] <- quantile(conLikeMod_diff_dist,0.05)
  conLikeMod_diff_data[i,"est"] <- quantile(conLikeMod_diff_dist,0.5)
  conLikeMod_diff_data[i,"upper90"] <- quantile(conLikeMod_diff_dist,0.95)
  conLikeMod_diff_data[i,"upper95"] <- quantile(conLikeMod_diff_dist,0.975)
}

conLikeModpr_prepost_vcov <- vcovHC(conLikeModpr_prepost, type="HC1")
conLikeModpr_prepost_betas <- rmvnorm(n=100000,mean=conLikeModpr_prepost$coefficients,sigma=conLikeModpr_prepost_vcov)
conLikeModpr_prepost_betas <- conLikeModpr_prepost_betas[,c("mrpr")]
conLikeModpr_prepost_data <- data.frame(dim="Pre-post 1",mrpr=1)
conLikeModpr_prepost_data$lower95 <- conLikeModpr_prepost_data$upper95 <- conLikeModpr_prepost_data$lower90 <- conLikeModpr_prepost_data$upper90 <- conLikeModpr_prepost_data$est <- NA
for(i in 1:nrow(conLikeModpr_prepost_data)){
  conLikeModpr_prepost_dist <- conLikeModpr_prepost_data[i,"mrpr"] * conLikeModpr_prepost_betas
  conLikeModpr_prepost_data[i,"lower95"] <- quantile(conLikeModpr_prepost_dist,0.025)
  conLikeModpr_prepost_data[i,"lower90"] <- quantile(conLikeModpr_prepost_dist,0.05)
  conLikeModpr_prepost_data[i,"est"] <- quantile(conLikeModpr_prepost_dist,0.5)
  conLikeModpr_prepost_data[i,"upper90"] <- quantile(conLikeModpr_prepost_dist,0.95)
  conLikeModpr_prepost_data[i,"upper95"] <- quantile(conLikeModpr_prepost_dist,0.975)
}

conLikeModpr_diff_vcov <- vcovHC(conLikeModpr_diff, type="HC1")
conLikeModpr_diff_betas <- rmvnorm(n=100000,mean=conLikeModpr_diff$coefficients,sigma=conLikeModpr_diff_vcov)
conLikeModpr_diff_betas <- conLikeModpr_diff_betas[,c("mrpr")]
conLikeModpr_diff_data <- data.frame(dim="Pre-post 2",mrpr=1)
conLikeModpr_diff_data$lower95 <- conLikeModpr_diff_data$upper95 <- conLikeModpr_diff_data$lower90 <- conLikeModpr_diff_data$upper90 <- conLikeModpr_diff_data$est <- NA
for(i in 1:nrow(conLikeModpr_diff_data)){
  conLikeModpr_diff_dist <- conLikeModpr_diff_data[i,"mrpr"] * conLikeModpr_diff_betas
  conLikeModpr_diff_data[i,"lower95"] <- quantile(conLikeModpr_diff_dist,0.025)
  conLikeModpr_diff_data[i,"lower90"] <- quantile(conLikeModpr_diff_dist,0.05)
  conLikeModpr_diff_data[i,"est"] <- quantile(conLikeModpr_diff_dist,0.5)
  conLikeModpr_diff_data[i,"upper90"] <- quantile(conLikeModpr_diff_dist,0.95)
  conLikeModpr_diff_data[i,"upper95"] <- quantile(conLikeModpr_diff_dist,0.975)
}

# Figure 1

lab_cont <- rbind(labLikeMod_prepost_data,labLikeMod_diff_data)
lab_pr <- rbind(labLikeModpr_prepost_data,labLikeModpr_diff_data)

con_cont <- rbind(conLikeMod_prepost_data,conLikeMod_diff_data)
con_pr <- rbind(conLikeModpr_prepost_data,conLikeModpr_diff_data)

pdf("plot_h1lab.pdf")
plot(NA,xlim = c(0.5,2.5),ylim = c(-0.4, 0.8), ylab = "Effect of moral rhetoric", xlab = "", xaxt = "n", cex.lab=1.5, cex.axis=1.3,main="Labour",cex.main=1.5)
axis(1, c(1,2), c("Pre-post 1","Pre-post 2"), cex.axis=1.3,cex.lab=1.5)
abline(h = 0,lty=2)
# pre-post 1
points(c(0.9,1.1),c(lab_cont[1,"est"],lab_pr[1,"est"]), pch=16, col = c("black","grey"))
segments(c(0.9,1.1),c(lab_cont[1,"lower95"],lab_pr[1,"lower95"]),
         c(0.9,1.1),c(lab_cont[1,"upper95"],lab_pr[1,"upper95"]),
         col = c("black","grey"), lwd = 1.5)
segments(c(0.9,1.1),c(lab_cont[1,"lower90"],lab_pr[1,"lower90"]),
         c(0.9,1.1),c(lab_cont[1,"upper90"],lab_pr[1,"upper90"]),
         col = c("black","grey"), lwd = 3)
# pre-post 2
points(c(1.9,2.1),c(lab_cont[2,"est"],lab_pr[2,"est"]), pch=16, col = c("black","grey"))
segments(c(1.9,2.1),c(lab_cont[2,"lower95"],lab_pr[2,"lower95"]),
         c(1.9,2.1),c(lab_cont[2,"upper95"],lab_pr[2,"upper95"]),
         col = c("black","grey"), lwd = 1.5)
segments(c(1.9,2.1),c(lab_cont[2,"lower90"],lab_pr[2,"lower90"]),
         c(1.9,2.1),c(lab_cont[2,"upper90"],lab_pr[2,"upper90"]),
         col = c("black","grey"), lwd = 3)
legend("topright",legend=c("moral vs. control","moral vs. pragmatic"),lty=c(1,1),col=c("black","grey"),bty="n",cex=1.3,lwd=2,pch=16)
dev.off()

pdf("plot_h1con.pdf")
plot(NA,xlim = c(0.5,2.5),ylim = c(-0.4, 0.8), ylab = "Effect of moral rhetoric", xlab = "", xaxt = "n", cex.lab=1.5, cex.axis=1.3,main="Conservative",cex.main=1.5)
axis(1, c(1,2), c("Pre-post 1","Pre-post 2"), cex.axis=1.3,cex.lab=1.5)
abline(h = 0,lty=2)
# pre-post 1
points(c(0.9,1.1),c(con_cont[1,"est"],con_pr[1,"est"]), pch=16, col = c("black","grey"))
segments(c(0.9,1.1),c(con_cont[1,"lower95"],con_pr[1,"lower95"]),
         c(0.9,1.1),c(con_cont[1,"upper95"],con_pr[1,"upper95"]),
         col = c("black","grey"), lwd = 1.5)
segments(c(0.9,1.1),c(con_cont[1,"lower90"],con_pr[1,"lower90"]),
         c(0.9,1.1),c(con_cont[1,"upper90"],con_pr[1,"upper90"]),
         col = c("black","grey"), lwd = 3)
# pre-post 2
points(c(1.9,2.1),c(con_cont[2,"est"],con_pr[2,"est"]), pch=16, col = c("black","grey"))
segments(c(1.9,2.1),c(con_cont[2,"lower95"],con_pr[2,"lower95"]),
         c(1.9,2.1),c(con_cont[2,"upper95"],con_pr[2,"upper95"]),
         col = c("black","grey"), lwd = 1.5)
segments(c(1.9,2.1),c(con_cont[2,"lower90"],con_pr[2,"lower90"]),
         c(1.9,2.1),c(con_cont[2,"upper90"],con_pr[2,"upper90"]),
         col = c("black","grey"), lwd = 3)
legend("topright",legend=c("moral vs. control","moral vs. pragmatic"),lty=c(1,1),col=c("black","grey"),bty="n",cex=1.3,lwd=2,pch=16)
dev.off()

###########################
# H2
###########################

# Labour: control vs. mr
h2labLike_prepost <- lm(likeL_post ~ mrcontrol * mftcare + likeL_pre, data=dat_lab)
h2labLike_diff <- lm(likeLdiff ~ mrcontrol * mftcare, data=dat_lab)

# Labour: pr vs. mr
h2labLikepr_prepost <- lm(likeL_post ~ mrpr * mftcare + likeL_pre, data=dat_lab)
h2labLikepr_diff <- lm(likeLdiff ~ mrpr * mftcare, data=dat_lab)

# Conservative: control vs. mr
h2conLike_prepost <- lm(likeC_post ~ mrcontrol * mftfair + likeC_pre, data=dat_con)
h2conLike_diff <- lm(likeCdiff ~ mrcontrol * mftfair, data=dat_con)

# Conservative: pr vs. mr
h2conLikepr_prepost <- lm(likeC_post ~ mrpr * mftfair + likeC_pre, data=dat_con)
h2conLikepr_diff <- lm(likeCdiff ~ mrpr * mftfair, data=dat_con)

# Figure 2

labMod_prepost <- interplot(h2labLike_prepost,"mrcontrol","mftcare",hist=T,sims = 100000) +
  geom_hline(yintercept = 0, colour = "grey60", linetype = 2) +
  labs(x="Care") +
  ggtitle("Moral vs. control: pre-post 1") +
  theme(axis.title=element_text(size=14),plot.title=element_text(size=14)) +
  theme_bw()  +
  theme(axis.line = element_line(color='black'),
        plot.background = element_blank(),
        panel.grid.minor = element_blank(),
        panel.grid.major = element_blank(),
        panel.border = element_blank(),
        axis.title=element_text(size=14),
        axis.text=element_text(size=14),
        plot.title=element_text(size=14))

conMod_prepost <- interplot(h2conLike_prepost,"mrcontrol","mftfair",hist=T,sims = 100000) +
  geom_hline(yintercept = 0, colour = "grey60", linetype = 2) +
  labs(x="Fairness") +
  ggtitle("Moral vs. control: pre-post 1") +
  theme(axis.title=element_text(size=14),plot.title=element_text(size=14)) +
  theme_bw()  +
  theme(axis.line = element_line(color='black'),
        plot.background = element_blank(),
        panel.grid.minor = element_blank(),
        panel.grid.major = element_blank(),
        panel.border = element_blank(),
        axis.title=element_text(size=14),
        axis.text=element_text(size=14),
        plot.title=element_text(size=14))

labModPr_prepost <- interplot(h2labLikepr_prepost,"mrpr","mftcare",hist=T,sims = 100000) +
  geom_hline(yintercept = 0, colour = "grey60", linetype = 2) +
  labs(x="Care") +
  ggtitle("Moral vs. pragmatic: pre-post 1") +
  theme(axis.title=element_text(size=14),plot.title=element_text(size=14)) +
  theme_bw()  +
  theme(axis.line = element_line(color='black'),
        plot.background = element_blank(),
        panel.grid.minor = element_blank(),
        panel.grid.major = element_blank(),
        panel.border = element_blank(),
        axis.title=element_text(size=14),
        axis.text=element_text(size=14),
        plot.title=element_text(size=14))

conModPr_prepost <- interplot(h2conLikepr_prepost,"mrpr","mftfair",hist=T,sims = 100000) +
  geom_hline(yintercept = 0, colour = "grey60", linetype = 2) +
  labs(x="Fairness") +
  ggtitle("Moral vs. pragmatic: pre-post 1") +
  theme(axis.title=element_text(size=14),plot.title=element_text(size=14)) +
  theme_bw()  +
  theme(axis.line = element_line(color='black'),
        plot.background = element_blank(),
        panel.grid.minor = element_blank(),
        panel.grid.major = element_blank(),
        panel.border = element_blank(),
        axis.title=element_text(size=14),
        axis.text=element_text(size=14),
        plot.title=element_text(size=14))

labMod_diff <- interplot(h2labLike_diff,"mrcontrol","mftcare",hist=T,sims = 100000) +
  geom_hline(yintercept = 0, colour = "grey60", linetype = 2) +
  labs(x="Care") +
  ggtitle("Moral vs. control: pre-post 2") +
  theme(axis.title=element_text(size=14),plot.title=element_text(size=14)) +
  theme_bw()  +
  theme(axis.line = element_line(color='black'),
        plot.background = element_blank(),
        panel.grid.minor = element_blank(),
        panel.grid.major = element_blank(),
        panel.border = element_blank(),
        axis.title=element_text(size=14),
        axis.text=element_text(size=14),
        plot.title=element_text(size=14))

conMod_diff <- interplot(h2conLike_diff,"mrcontrol","mftfair",hist=T,sims = 100000) +
  geom_hline(yintercept = 0, colour = "grey60", linetype = 2) +
  labs(x="Fairness") +
  ggtitle("Moral vs. control: pre-post 2") +
  theme(axis.title=element_text(size=14),plot.title=element_text(size=14)) +
  theme_bw()  +
  theme(axis.line = element_line(color='black'),
        plot.background = element_blank(),
        panel.grid.minor = element_blank(),
        panel.grid.major = element_blank(),
        panel.border = element_blank(),
        axis.title=element_text(size=14),
        axis.text=element_text(size=14),
        plot.title=element_text(size=14))

labModPr_diff <- interplot(h2labLikepr_diff,"mrpr","mftcare",hist=T,sims = 100000) +
  geom_hline(yintercept = 0, colour = "grey60", linetype = 2) +
  labs(x="Care") +
  ggtitle("Moral vs. pragmatic: pre-post 2") +
  theme(axis.title=element_text(size=14),plot.title=element_text(size=14)) +
  theme_bw()  +
  theme(axis.line = element_line(color='black'),
        plot.background = element_blank(),
        panel.grid.minor = element_blank(),
        panel.grid.major = element_blank(),
        panel.border = element_blank(),
        axis.title=element_text(size=14),
        axis.text=element_text(size=14),
        plot.title=element_text(size=14))

conModPr_diff <- interplot(h2conLikepr_diff,"mrpr","mftfair",hist=T,sims = 100000) +
  geom_hline(yintercept = 0, colour = "grey60", linetype = 2) +
  labs(x="Fairness") +
  ggtitle("Moral vs. pragmatic: pre-post 2") +
  theme(axis.title=element_text(size=14),plot.title=element_text(size=14)) +
  theme_bw()  +
  theme(axis.line = element_line(color='black'),
        plot.background = element_blank(),
        panel.grid.minor = element_blank(),
        panel.grid.major = element_blank(),
        panel.border = element_blank(),
        axis.title=element_text(size=14),
        axis.text=element_text(size=14),
        plot.title=element_text(size=14))

pdf(file="plot_h2lab.pdf",width=10,height=8)
annotate_figure(ggarrange(labMod_prepost,labMod_diff,labModPr_prepost,labModPr_diff,
                          ncol=2,nrow=2),
                top=text_grob("Labour Party Experiment\n",size=14,face="bold"),
                left=text_grob("Effect of moral rhetoric",size=14,rot=90))
dev.off()

pdf(file="plot_h2con.pdf",width=10,height=8)
annotate_figure(ggarrange(conMod_prepost,conMod_diff,conModPr_prepost,conModPr_diff,
                          ncol=2,nrow=2),
                top=text_grob("Conservative Party Experiment\n",size=16,face="bold"),
                left=text_grob("Effect of moral rhetoric",size=16,rot=90))
dev.off()

# Labour: average effect size using respondents with value of 4.25 or above on Care

summary(lm(likeLdiff ~ mrcontrol, data=subset(dat_lab,mftcare>=4.25)))
t.test(subset(dat_lab,mftcare>=4.25&mrcontrol==0)$likeLdiff,subset(dat_lab,mftcare>=4.25&mrcontrol==1)$likeLdiff)
es1 <- diff(t.test(subset(dat_lab,mftcare>=4.25&mrcontrol==0)$likeLdiff,subset(dat_lab,mftcare>=4.25&mrcontrol==1)$likeLdiff)$estimate)/
  sd(subset(dat_lab,!is.na(mrcontrol))$likeLdiff)

summary(lm(likeLdiff ~ mrpr, data=subset(dat_lab,mftcare>=4.25)))
t.test(subset(dat_lab,mftcare>=4.25&mrpr==0)$likeLdiff,subset(dat_lab,mftcare>=4.25&mrpr==1)$likeLdiff)
es2 <- diff(t.test(subset(dat_lab,mftcare>=4.25&mrpr==0)$likeLdiff,subset(dat_lab,mftcare>=4.25&mrpr==1)$likeLdiff)$estimate)/
  sd(subset(dat_lab,!is.na(mrpr))$likeLdiff)

summary(lm(likeL_post ~ mrcontrol + likeL_pre, data=subset(dat_lab,mftcare>=4.25)))
es3 <- summary(lm(likeL_post ~ mrcontrol + likeL_pre, data=subset(dat_lab,mftcare>=4.25)))$coef[2,1]/
  sd(subset(dat_lab,!is.na(mrcontrol))$likeLdiff)

summary(lm(likeL_post ~ mrpr + likeL_pre, data=subset(dat_lab,mftcare>=4.25)))
t.test(subset(dat_lab,mftcare>=4.25&mrpr==0)$likeLdiff,subset(dat_lab,mftcare>=4.25&mrpr==1)$likeLdiff)
es4 <- summary(lm(likeL_post ~ mrpr + likeL_pre, data=subset(dat_lab,mftcare>=4.25)))$coef[2,1]/
  sd(subset(dat_lab,!is.na(mrpr))$likeLdiff)

mean(c(es1,es2,es3,es4))

###########################
# H3
###########################

# Labour
h3labLike_diff <- lm(likeLdiff ~ mrcontrol * dislikeL_pre, data=dat_lab)
h3labLikepr_diff <- lm(likeLdiff ~ mrpr * dislikeL_pre, data=dat_lab)

# Conservative
h3conLike_diff <- lm(likeCdiff ~ mrcontrol * dislikeC_pre, data=dat_con)
h3conLikepr_diff <- lm(likeCdiff ~ mrpr * dislikeC_pre, data=dat_con)

# Figure 3

labMod_diff <- interplot(h3labLike_diff,"mrcontrol","dislikeL_pre",hist=T,sims = 100000) +
  geom_hline(yintercept = 0, colour = "grey60", linetype = 2) +
  labs(x="Dislike of Labour Party") +
  ggtitle("Moral vs. control: pre-post 2") +
  theme(axis.title=element_text(size=14),plot.title=element_text(size=14)) +
  theme_bw()  +
  theme(axis.line = element_line(color='black'),
        plot.background = element_blank(),
        panel.grid.minor = element_blank(),
        panel.grid.major = element_blank(),
        panel.border = element_blank(),
        axis.title=element_text(size=16),
        axis.text=element_text(size=14),
        plot.title=element_text(size=16))

conMod_diff <- interplot(h3conLike_diff,"mrcontrol","dislikeC_pre",hist=T,sims = 100000) +
  geom_hline(yintercept = 0, colour = "grey60", linetype = 2) +
  labs(x="Dislike of Conservative Party") +
  ggtitle("Moral vs. control: pre-post 2") +
  theme(axis.title=element_text(size=14),plot.title=element_text(size=14)) +
  theme_bw()  +
  theme(axis.line = element_line(color='black'),
        plot.background = element_blank(),
        panel.grid.minor = element_blank(),
        panel.grid.major = element_blank(),
        panel.border = element_blank(),
        axis.title=element_text(size=16),
        axis.text=element_text(size=14),
        plot.title=element_text(size=16))

labModPr_diff <- interplot(h3labLikepr_diff,"mrpr","dislikeL_pre",hist=T,sims = 100000) +
  geom_hline(yintercept = 0, colour = "grey60", linetype = 2) +
  labs(x="Dislike of Labour Party") +
  ggtitle("Moral vs. pragmatic: pre-post 2") +
  theme(axis.title=element_text(size=14),plot.title=element_text(size=14)) +
  theme_bw()  +
  theme(axis.line = element_line(color='black'),
        plot.background = element_blank(),
        panel.grid.minor = element_blank(),
        panel.grid.major = element_blank(),
        panel.border = element_blank(),
        axis.title=element_text(size=16),
        axis.text=element_text(size=14),
        plot.title=element_text(size=16))

conModPr_diff <- interplot(h3conLikepr_diff,"mrpr","dislikeC_pre",hist=T,sims = 100000) +
  geom_hline(yintercept = 0, colour = "grey60", linetype = 2) +
  labs(x="Dislike of Conservative Party") +
  ggtitle("Moral vs. pragmatic: pre-post 2") +
  theme(axis.title=element_text(size=14),plot.title=element_text(size=14)) +
  theme_bw()  +
  theme(axis.line = element_line(color='black'),
        plot.background = element_blank(),
        panel.grid.minor = element_blank(),
        panel.grid.major = element_blank(),
        panel.border = element_blank(),
        axis.title=element_text(size=16),
        axis.text=element_text(size=14),
        plot.title=element_text(size=16))

pdf(file="plot_h3lab.pdf",width=10,height=6)
annotate_figure(ggarrange(labMod_diff,labModPr_diff,ncol=2,nrow=1),
                top=text_grob("Labour Party Experiment\n",size=14,face="bold"),
                left=text_grob("Effect of moral rhetoric",size=16,rot=90))
dev.off()

pdf(file="plot_h3con.pdf",width=10,height=6)
annotate_figure(ggarrange(conMod_diff,conModPr_diff,ncol=2,nrow=1),
                top=text_grob("Conservative Party Experiment\n",size=14,face="bold"),
                left=text_grob("Effect of moral rhetoric",size=16,rot=90))
dev.off()




